<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>

    //  1+2+3+4+5 + ....  10    函数

    // function sum(number) {
    //     var sum = 0
    //     for (let i = 1; i <= number; i++) {
    //         sum += i
    //     }
    //     return sum;
    // }

    // 递归    一定要有结束条件
    function sum(number) {

        if (number == 1) {
            return 1
        }
        return number + sum(number - 1)
    }


    // 5!
    function jc(number) {

        if (number == 1) {
            return 1
        }

        return number * jc(number - 1)
    }

    console.log(sum(100));
    console.log(jc(5))

    //  sum(5) = 5+ sum(4)   sum(4) = 4+sum(3)

</script>

</body>
</html>